package com.juli.aimanager.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

public class DateChosenUtil {
	/**
	 * 获取上个月月份
	 * @param date
	 * @return
	 */
	public static String getLastMonth(Date date){
		SimpleDateFormat simple=new SimpleDateFormat("yyyyMM");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, -1);
       
        return  simple.format(cal.getTime());
	}
	
	
	/**
	 * 获取上个月的第一天
	 * @param date
	 * @return
	 */
	public static String getLastMonthFirstDate(Date date) {
		SimpleDateFormat simple=new SimpleDateFormat("yyyy-MM");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, -1);
       
        return  simple.format(cal.getTime())+"-01";
    }
	/**
	 * 得到当月的第一天
	 * @param date
	 * @return
	 */
	public static String getThisMonthFirstDate(Date date) {
		SimpleDateFormat simple=new SimpleDateFormat("yyyy-MM");
         return  simple.format(date)+"-01";
    }
	/**
	 * 按照给定的格式，格式化日期
	 * @param formater	需要的格式，常用的例如"yyyy-MM-dd HH:mm:ss"
	 * @param date  日期
	 * @return
	 */
	public static String formatFromDate(String formater, Date date){
		DateFormat df = new SimpleDateFormat(formater);
		return df.format(date);
	}
	public static Map<String, String> returnDateType(Map<String, String> paramsMap){
		String dateType=paramsMap.get("dateType")==null?"":paramsMap.get("dateType")+"";
		SimpleDateFormat simple=new SimpleDateFormat("yyyy-MM-dd");
		if(dateType==null){
			return  paramsMap;
		}
		if(dateType.equals("")){
			return  paramsMap;
		}
		if(dateType.equals("0")){
			paramsMap.put("startdate", simple.format(new Date()));
			paramsMap.put("enddate", simple.format(new Date()));
			
		}
		if(dateType.equals("1")){
			Calendar cal=Calendar.getInstance();
			cal.setTime(new Date());
			cal.add(Calendar.DATE, -1);
			paramsMap.put("startdate", simple.format(cal.getTime()));
			paramsMap.put("enddate", simple.format(cal.getTime()));
			
		}
		if(dateType.equals("2")){
			Calendar cal=Calendar.getInstance();
			cal.setTime(new Date());
			cal.add(Calendar.DATE, -7);
			paramsMap.put("startdate", simple.format(cal.getTime()));
			paramsMap.put("enddate", simple.format(new Date()));
		}
		if(dateType.equals("3")){
			Calendar cal=Calendar.getInstance();
			cal.setTime(new Date());
			cal.add(Calendar.DATE, -31);
			paramsMap.put("startdate", simple.format(cal.getTime()));
			paramsMap.put("enddate", simple.format(new Date()));
		}
		if(dateType.equals("4")){
			paramsMap.put("startdate", "2015-11-15");
			paramsMap.put("enddate", "2016-03-15");
		}
		if(dateType.equals("5")){
			
		}
		System.out.println(paramsMap);
		return paramsMap;
	}
	public static String getDate(int num){
		Calendar   cal   =   Calendar.getInstance();
		cal.add(Calendar.DATE,   num);
		Date date=cal.getTime();
	    String day = new SimpleDateFormat( "yyyy-MM-dd ").format(date);
		return day;
	}

}
